package com.employees.action;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.employees.bean.Employee;
import com.employees.bean.EmployeeBase;
import com.employees.bean.Employeeinfo;
import com.employees.bean.Pager;
import com.employees.bean.Result;
import com.employees.service.EmployeeService;

public class EmployeePager extends Action {
	
	private int page;

	private EmployeeService employeeService;

	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		
		Pager pager=new Pager();
		pager.setEveryPage(10);//设置每页显示的条数
		String p=request.getParameter("currentPage");
		if (p != null) {
			page = Integer.parseInt(p);
		} else {
			page = 1;
		}
		pager.setCurrentPage(page);//为第一页
		String hql="from Employee  employee,Employeeinfo  employeeinfo,Employeeskill employeeskill where employee.no=employeeinfo.employee.no and employee.no=employeeskill.employee.no";
		Result result=employeeService.findByPage(pager,hql);
		request.setAttribute("list",result.getList());
		request.setAttribute("pager", result.getPager());
		return mapping.findForward("success");
	}
}
